package com.zx.mobile.service.proxy;

import com.zx.map.service.model.ConsumeLogModel;
import com.zx.mobile.domain.pingan.UserAcctChargeRequest;
import com.zx.platform.utils.PmpUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

public class PAUserAcctChargeCommonProxy {

	/**
	 * 平安消费充值合法性校验
	 * 
	 * @return
	 */
	public static String checkUserAcctCharge(
			UserAcctChargeRequest userAcctChargeRequest) {
		if (StringUtils.isBlank(userAcctChargeRequest.getPartnerId())) {
			return "输入项必填";
		}
		if (StringUtils.isBlank(userAcctChargeRequest.getSign())) {
			return "输入项必填";
		}
		if (StringUtils.isBlank(userAcctChargeRequest.getUserId())) {
			return "输入项必填";
		}
		if (StringUtils.isBlank(userAcctChargeRequest.getOrderId())) {
			return "输入项必填";
		}
		if (StringUtils.isBlank(userAcctChargeRequest.getRandomKey())) {
			return "输入项必填";
		}
		if (StringUtils.isBlank(userAcctChargeRequest.getTradeAmt())) {
			return "输入项必填";
		}
		if (StringUtils.isBlank(userAcctChargeRequest.getVerifyCode())) {
			return "输入项必填";
		}
		if (StringUtils.isBlank(userAcctChargeRequest.getTelephone())) {
			return "输入项必填";
		}
		// 签名验证
		if (!PASignHelper.checkRequestSign(userAcctChargeRequest,
				userAcctChargeRequest.getSign())) {
			return "签名验证失败";
		}

		if (StringUtils.isBlank(userAcctChargeRequest.getVerifyCode())) {
			return "输入项必填";
		}
		return null;
	}

	/**
	 * 平安消费充值模态转换
	 * 
	 * @return
	 */
	public static ConsumeLogModel transformUserAcctCharge(
			UserAcctChargeRequest userAcctChargeRequest,String merchantId) {
		ConsumeLogModel temp = new ConsumeLogModel();
		temp.setUserId(userAcctChargeRequest.getUserId());
		temp.setConsumeId(PmpUtils.getConsumeOrderNum());
		temp.setConsumeAmt(Double.valueOf(userAcctChargeRequest.getTradeAmt()));
		temp.setCreateDate(new Date());
		temp.setMerchantId(merchantId);
		temp.setMerSysAccount(userAcctChargeRequest.getTelephone());
		temp.setAccessOrdId(userAcctChargeRequest.getOrderId());
		temp.setAccessTradeAmt(Double.valueOf(userAcctChargeRequest
				.getTradeAmt()));
		temp.setRandomKey(userAcctChargeRequest.getRandomKey());
		return temp;
	}
}
